#pragma
#include <iostream>
#include <ctemplate/template.h>
#include "model.hpp"

namespace ns_view
{

    using namespace std;
    using namespace ns_model;
    using namespace ctemplate;

    class View
    {

    public:
        View()
        {
        }

        ~View() {}

        // string id;
        // string titlename;
        // string level;
        const string filepath = "./template_html";

        void ExpandAllToHtml(string &out_html, vector<Question> &vsq)
        {
            // 形成数据字典
            ctemplate::TemplateDictionary root("all_questions");
            for (auto &q : vsq)
            {
                TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q.number);
                sub->SetValue("star", q.star);
                sub->SetValue("title", q.title);
            }

            Template* tpl = Template::GetTemplate(filepath + "/QuestionList.html", DO_NOT_STRIP);
            tpl->Expand(&out_html, &root);
        }

        void ExpandOneToHtml(string &out_html, Question &q)
        {
            TemplateDictionary root("one");
            root.SetValue("number", q.number);
            root.SetValue("star", q.star);
            root.SetValue("title", q.title);
            root.SetValue("desc", q.desc);
            root.SetValue("pre_code", q.header);
            

            Template *tpl = Template::GetTemplate(filepath + "/OneQuestion.html", DO_NOT_STRIP);
            tpl->Expand(&out_html, &root);
        }
    };

}